<?php
namespace PsiFramework\Applications\DefaultApp\Classes\DAO;

import("Classes.DAO.AbstractDAO");
import("Applications.DefaultApp.Classes.Model.Text");

use \PsiFramework\Classes\DAO\AbstractDAO;
use \PsiFramework\Classes\Util\Parameters\ObjectParameters;
use \PsiFramework\Applications\DefaultApp\Classes\Model\Text;
use \PsiFramework\Classes\Util\Database\Builder\QueryBuilder;
use \PsiFramework\Classes\Util\Database\Query\SqlColumn;
use \PsiFramework\Classes\Util\Database\Query\SqlFunction;
use \PsiFramework\Classes\Util\Database\Query\SqlOperation;
use \PsiFramework\Classes\Util\Database\Query\SqlTable;
use \PsiFramework\Classes\Util\Database\Query\SqlValue;
use \PsiFramework\Classes\Util\Database\Filters\QueryFilter;

/**
 * PsiFramework
 * Php Simple Framework
 *
 * @author Rémi San
 * @version beta
 */

/**
 * The TextDAO class is the Data Access Object for the Texts
 *
 * @package DAO
 */
class TextDAO extends AbstractDAO
{

    protected static $_singleton = null;

    public function retrieveByPartialName(/*string*/ $partialName)
    {
    
    	$colNom = new SqlColumn("fr");
    	$value = '%' ;    if (!isNullOrEmptyString($partialName)) {
    		$value .= mb_strtoupper($partialName, 'utf-8') . "%" ;
    	}
    	$sqlValue = new SqlValue($value);
    
    	$upper = new SqlFunction("UPPER");
    	$upper->addParameter($colNom);
    
    	$like = new SqlOperation(SqlOperation::$like);
    	$like->addParameter($upper);
    	$like->addParameter($sqlValue);
    
    	return $this->retrieveAll(new QueryFilter($like));
    
    }

    /**
     * Function to be called instead of the constructor.
     *
     * @return CityDAO instance
     */
    public static function getInstance(ObjectParameters $objectParameters)
    {

        if (self::$_singleton==null) {
            self::$_singleton = new TextDAO($objectParameters);
        }

        return self::$_singleton;
    }
}
